import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/*
* ServletContext对象
* 概念：代表整个web应用，可以和程序的容器（程序在tomcat）来通信
* 通信就是数据存储 取出来
*
* 功能：
* 1.域对象：共享数据 最大的域
* 2.获取文件真实路径 http：//locahost：//虚拟路径/资源路径或者页面
*
*获取：
* 1.通过reques对象获取
* req.getServeltContext();
* 2.通过HttpServlet
* this.getServletContext()
* */
@WebServlet("/servleContextDemo1")
public class ServletContextDemo1 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*1.通过request对象获取*/
        ServletContext context1= req.getServletContext();
        /*通过httpServlet来获取*/
        ServletContext context2=this.getServletContext();
        System.out.println(context1);
        System.out.println(context2);
        System.out.println(context1==context2);

    }
}
